package demo;

/**
 * @author ZhouWeiBo
 * @create 2022/6/8
 */
public class FreeBusContext {

    private final Expression expression;

    /**
     * 免费乘车人群
     */
    private static final Role[] FREE_ROLE = {Role.OLD_MAN,Role.CHILD,Role.PREGNANT_WOMAN,Role.HANDICAPPED};

    /**
     * 免费乘车城市
     */
    private static final City[] FREE_CITY = {City.BEIJING,City.SHANGHAI,City.GUANGZHOU,City.SHENZHEN};

    public FreeBusContext() {
        RoleExpression roleExpression = new RoleExpression(FREE_ROLE);
        CityExpression cityExpression = new CityExpression(FREE_CITY);
        this.expression = new NonTerminalExpression(roleExpression,cityExpression);
    }

    public boolean isFree(Person person){
        return expression.interpret(person);
    }
}
